<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>修改工作经历</title>
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
	<link rel="stylesheet" href="css/mui.min.css" />
	<!-- build:css css/app.css -->
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/common.css" />
	<!-- endbuild -->
	<style>
		.resume-list .wrapper {
			padding-top: 15px;
			padding-bottom: 1px;
		}

		.resume-list:last-child .wrapper {
			border-bottom: 0;
		}
	</style>
</head>

<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">修改工作经历</h1>
	</header>
	<div class="mui-content">
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>入职时间</label>
				<input id="entry-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>离职时间</label>
				<input id="overy-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label>
					<span class="red">*</span>公司名称
				</label>
				<input id="comp-name" type="text" placeholder="请填写" />
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label>
					<span class="red">*</span>职位
				</label>
				<input id="position" type="text" placeholder="请填写" />
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>公司性质</label>
				<input id="comp-type" type="text" placeholder="请选择" />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>公司规模</label>
				<input id="comp-scale" type="text" placeholder="请选择" />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper">
				<label>工作内容</label>
			</div>
			<textarea id="work-content" placeholder="请填写"></textarea>
		</div>
		<button id="save" class="button button-blue">保存</button>
	</div>
	<script src="js/mui.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
	<!-- build:js js/app.js -->
	<script src="js/api.js"></script>
	<script src="js/tools.js"></script>
	<!-- endbuild -->
	<script>
		var href = window.location.href;
		var hid = 0;
		var data = {
			entryTime: null,
			leaveTime: null,
			workCompanyName: '',
			workPosition: '',
			companyNature: null,
			companyScale: null,
			workContent: ''
		}
		if (href.indexOf('?') != -1) {
			hid = href.split('?')[1].split('=')[1];
		}
		function init(res) {
			if (res['entryTime']) {
				data.entryTime = res['entryTime'];
				$('#entry-time').val(res['entryTime'])
			}
			if (res['leaveTime']) {
				data.leaveTime = res['leaveTime'];
				$('#overy-time').val(res['leaveTime'])
			}
			if (res['workCompanyName']) {
				data.workCompanyName = res['workCompanyName'];
				$('#comp-name').val(res['workCompanyName'])
			}
			if (res['workPosition']) {
				data.workPosition = res['workPosition'];
				$('#position').val(res['workPosition'])
			}
			if (res['companyNature']) {
				data.companyNature = res['companyNature'];
				$('#comp-type').val(config.compType[res['companyNature']])
			}
			if (res['companyScale']) {
				data.companyScale = res['companyScale'];
				$('#comp-scale').val(config.companyScale[res['companyScale']])
			}
			if (res['workContent']) {
				data.workContent = res['workContent'];
				$('#work-content').val(res['workContent'])
			}
		}
		// 回显
		$.ajax({
			url: config.ME_API + 'h5/h5GetHistory',
			type: 'post',
			data: {
				hid: hid
			},
			success: function (res) {
				if (res.code == 2) {
					init(res.data.history)
				} else {
					mui.toast(res.msg)
				}
			}
		})
		// 入职时间
		$("#entry-time").calendar({
			onChange: function (p, values, displayValues) {
				data.entryTime = values[0].replace(/\//g, '-')
			}
		});
		// 离职时间
		$("#overy-time").calendar({
			onChange: function (p, values, displayValues) {
				data.leaveTime = values[0].replace(/\//g, '-')
			}
		});
		// 公司性质
		$('#comp-type').picker({
			title: '公司性质',
			cols: [
				{
					textAlign: 'center',
					values: config.compType
				}
			],
			onChange: function (e) {
				data.companyNature = e.cols[0]['activeIndex']
			}
		})
		// 公司规模
		$('#comp-scale').picker({
			title: '公司规模',
			cols: [
				{
					textAlign: 'center',
					values: config.companyScale
				}
			],
			onChange: function (e) {
				data.companyScale = e.cols[0]['activeIndex']
			}
		})
		// 保存
		$('#save').on('tap', function () {
			data.workCompanyName = $('#comp-name').val();
			data.workPosition = $('#position').val();
			data.workContent = $('#work-content').val();
			data.hid = hid;

			console.log(data);
			if (data['entryTime'] == null) {
				mui.toast('请选择入职时间!');
				return false
			}
			if (data['leaveTime'] == null) {
				mui.toast('请选择离职时间!');
				return false
			}
			if (data['workCompanyName'] == '') {
				mui.toast('请输入公司名称!');
				return false
			}
			if (data['workPosition'] == '') {
				mui.toast('请输入职位!');
				return false
			}
			if (data['companyNature'] == null) {
				mui.toast('请选择公司性质!');
				return false
			}
			if (data['companyScale'] == null) {
				mui.toast('请选择公司规模!');
				return false
			}
			if (data['workContent'] == '') {
				mui.toast('请输入工作内容!');
				return false
			}
			if (!isLogin()) {
				mui.toast('请先登录!');
				return false
			}
			$.ajax({
				url: config.ME_API + 'h5/h5EditHistory',
				type: 'post',
				data: data,
				success: function (res) {
					if (res.code == 2) {
						mui.toast('修改成功!');
						setTimeout(function () {
							window.history.back()
						}, 1000)
						console.log(res)
					} else {
						mui.toast(res.msg)
					}
				}
			})
		})
	</script>
</body>

</html>